home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir36 / ask_dos.zip / ASK.DOC < prev    next >
Text File  |  1994-03-05  |  6KB  |  171 lines

  1.  
  2.                             ASK.COM - Batch Enhancer
  3.  
  4.                            Written By: Patrick Whittle
  5.  
  6.  
  7. Introduction:▐
  8. ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  9.  
  10. The program ASK.COM was assembled using Borland Turbo Assembler. It is fully 
  11. compatible with any 8086 or greater processor.  It is meant for exclusive use 
  12. in DOS batch files.
  13.  
  14. The source code and documentation has been supplied for any one new to PC
  15. assembly language who may wish to learn to program themselves, in assembler.
  16. Most functions used in this program are fairly simple, but you should be some-
  17. what familiar with the Intel instruction set architecture first before diving
  18. into the code.
  19.  
  20. The technique of replacing an interrupt handler was included to demonstrate
  21. the power of assembler programming, to introduce the reader to the concept 
  22. of the interrupt vector table, and to show the interrupt structure of the 
  23. Intel 80XXX family of processors.  The most practicle use for code such as 
  24. this is in the writing of software device drivers, and TSRs.
  25.  
  26. While the operating systems emerging today like OS/2 and UNIX for the micro-
  27. computer are very advanced, programming in assembler language may not be
  28. necessary in the near future; but the writing of device drivers will
  29. surely be around for quite a while on these systems.  Learning some of the
  30. techniques and methods first under DOS is a fundamental stepping stone.
  31.  
  32.  
  33. Details:▐
  34. ▀▀▀▀▀▀▀▀▀
  35.  
  36. To generate an errorlevel code for the Ctrl-C combination which can be
  37. checked via 'IF errorlevel' commands in DOS batch files, DOS functions 35h
  38. and 25h are used to replace the Ctrl-C interrupt handler.  This technique is
  39. accomplished by using function 35h of int 21h to first save the default 
  40. interrupt handler, and later using function 25h to restore.
  41.  
  42. Function 25h of int 21h will set or modify an interrupt handler with a 
  43. segment:offset value passed via DS:DX registers. The values placed in DS:DX
  44. before calling function 25h in the context of this program, are addresses 
  45. contained within the executable ASK.COM.  The ctrlBreakHandler PROCedure
  46. in the source file ASK.ASM will take over the Ctrl-C interrupt after function
  47. 25h has been initiated.
  48.  
  49. Before termination of the program, function 25h will be used again to restore 
  50. the default handler to point to machine code originally intended for use on
  51. the occurrence of the Ctrl-Break interrupt (this code will display the familiar
  52. prompt "Terminate batch job (Y/N)?" on the screen).
  53.  
  54.  
  55.                
  56. Using ASK.COM:▐
  57. ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  58.  
  59. ASK can be used with or without a command-line parameter.  Omitting the
  60. command-line parameter will simply send a (Y or N)? prompt to the screen.
  61. The length of parameter used with ASK is restricted to 127 bytes, as DOS
  62. disallows further input at this point.
  63.  
  64. Following are examples for its use:
  65.  
  66. Example 1:
  67.         . . .
  68.         ASK Do you wish to run Microsoft Windows?
  69.         IF errorlevel == 2 goto CTRL_C
  70.         IF errorlevel == 1 goto ABORT
  71.         win %1 %2 %3
  72.         goto END
  73.  
  74.         :ABORT
  75.         echo Returning to DOS.
  76.         goto END
  77.         
  78.         :CTRL_C
  79.         echo Routine aborted.
  80.         . . .
  81.  
  82.         :END
  83.  
  84. Example 2:
  85.         
  86.         :ENTRY_POINT
  87.         ASK Do you wish to run Microsoft Windows?
  88.         IF errorlevel == 2 goto ENTRY_POINT
  89.         IF errorlevel == 1 goto ABORT
  90.         win %1 %2 %3
  91.         goto END
  92.  
  93.         :ABORT
  94.         echo Returning to DOS.
  95.         goto END
  96.         . . .
  97.  
  98.         :END
  99.  
  100. The reason Ctrl-C was replaced in this program is to broaden the trapping
  101. mechanism during user input.  If Ctrl-C was allowed to interrupt during the
  102. input state of ASK, the user could then terminate the batch file.
  103.  
  104.  
  105.  
  106. DOS Batch files:▐
  107. ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  108.  
  109. DOSs batch language has some restrictions in its use that must be clearly
  110. understood.  When entering an IF-THEN-ELSE type structure in a batch file
  111. in the IF errorlevel form, you MUST check the highest possible errorlevel
  112. first, followed by the next highest, etc. This is to ensure the conditional
  113. block will branch correctly.
  114.  
  115. Secondly, you cannot check for a zero errorlevel.  A zero errorlevel must
  116. be handled in a CASE ELSE form as the example below illustrates:
  117.  
  118.         IF errorlevel == 4 goto OPTION4
  119.         IF errorlevel == 3 goto OPTION3
  120.         IF errorlevel == 2 goto OPTION2
  121.         IF errorlevel == 1 goto OPTION1
  122.  
  123.         :ELSE
  124.         command %1 %2 %3
  125.         goto END
  126.  
  127. The following table illustrates in graphic form, the related errorlevels
  128. returned from ASK.COM, the appropriate action, and DOS syntax to accomplish
  129. a certain conditional block:
  130.  
  131.  
  132. Exit codes:▐
  133. ▀▀▀▀▀▀▀▀▀▀▀▀
  134.  
  135. ╒════════╤═══════════════╤═══════════════════════════════════════════════════╕
  136. │ Error  │  Keystroke/   │   DOS Batch File Syntax:                          │
  137. │ Level  │  Combination  │                                                   │
  138. ╞════════╪═══════════════╪═══════════════════════════════════════════════════╡
  139. │        │               │                                                   │
  140. │   2    │  Ctrl-Break   │  IF errorlevel == 2 goto CTRL_C_ROUTINE           │
  141. │        │               │                                                   │
  142. │   1    │  N (no)       │  IF errorlevel == 1 goto FALSE_LABEL              │
  143. │        │               │                                                   │
  144. │   0    │  Y (yes)      │  Here errorlevel = 0, so execute true statements  │ 
  145. │        │               │                                                   │
  146. └────────┴───────────────┴───────────────────────────────────────────────────┘
  147.  
  148. Option:▐
  149. ▀▀▀▀▀▀▀▀
  150.  
  151. /?  display ask info
  152.  
  153.  
  154.  
  155.  
  156. References:▐
  157. ▀▀▀▀▀▀▀▀▀▀▀▀
  158.  
  159. There are many great books on assembler programming and the writing of device
  160. drivers and TSRs.  Two books I use frequently are:
  161.  
  162. 1. "PC Interrupts" A Programmers Reference by Ralf Brown, and Jim Kyle
  163.          Addison-Wesley Publishing Company, Inc., 1991
  164.          ISBN 0-201-57797-6
  165.  
  166. 2. "Assembly Language Programming for the Intel 80XXX Family" by William Giles,
  167.          Macmillan Publishing Company, New York, 1991
  168.          ISBN 0-02-342990-9
  169.  
  170.  
  171.